package com.tjf.lib_core.views;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.tjf.lib_core.R;

public class TitleBar extends LinearLayout {
    TextView titleName;
    TextView titleFarm;
    ImageView titleBack;

    public TitleBar(Context context) {
        this(context, null);
    }

    public TitleBar(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TitleBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    void init(Context context) {
        View parentView = LayoutInflater.from(context).inflate(R.layout.title_bar, null);
        titleBack = parentView.findViewById(R.id.title_img_back);
        titleName = parentView.findViewById(R.id.title_name_tv);
        titleFarm = parentView.findViewById(R.id.title_pasture_tv);
        addView(parentView);


    }


    public void setTitleBack(boolean isHideBack) {
        this.titleBack.setVisibility(isHideBack ? View.INVISIBLE : VISIBLE);
    }

    public void setTitleName(String titleName) {
        this.titleName.setText(titleName);
    }

    public void setTitleFarm(String titleFarm) {
        this.titleFarm.setText(titleFarm);
    }

    public void onTitleBack(OnClickListener onClickListener) {
        Log.i("点击了", "返回");
        titleBack.setOnClickListener(onClickListener);
    }

    public void onTitleFarm(OnClickListener onClickListener) {
        Log.i("点击了", "牧场名");
        titleFarm.setOnClickListener(onClickListener);
    }

    public TextView getTitleName() {
        return titleName;
    }

    public TextView getTitleFarm() {
        return titleFarm;
    }

    public ImageView getTitleBack() {
        return titleBack;
    }
}
